package com.handpay.nocardpay.baselibrary.pay.unipay.view.fragment;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;

/**
 * Created by lyang on 2017/8/16.
 */

public class ShowHTMLFragment extends BaseFragment {
    public static final String SHOW_HTML_TITLE = "SHOW_HTML_TITLE";
    public static final String SHOW_HTML_URL = "SHOW_HTML_URL";
    private  WebView mWebView;
    public static ShowHTMLFragment newInstance(String title, String url) {
        Bundle args = new Bundle();
        args.putString(SHOW_HTML_TITLE, title);
        args.putString(SHOW_HTML_URL, url);
        ShowHTMLFragment fragment = new ShowHTMLFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_show_html;
    }

    @Override
    public void initView(View view) {
        Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
        initToolbar(toolbar, true);
         mWebView = (WebView) view.findViewById(R.id.url_body_web_view);
        // 开启 localStorage
        mWebView.getSettings().setDomStorageEnabled(true);
        // 设置支持javascript
        mWebView.getSettings().setJavaScriptEnabled(true);
        // 启动缓存
        mWebView.getSettings().setAppCacheEnabled(true);
        // 设置缓存模式
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        //使用自定义的WebViewClient
        mWebView.setWebViewClient(new WebViewClient() {
            //覆盖shouldOverrideUrlLoading 方法
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

    }


    @Override
    public void initListener() {

    }

    @Override
    public String getFragmentTitle() {
        return getArguments().getString(SHOW_HTML_TITLE);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        String url = getArguments().getString(SHOW_HTML_URL);
        mWebView.loadUrl(url);
    }
}